<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>

  <style>
    #parent-host::shadow p {
      /* shadow 只能跨一层 */
      background: rgba(0, 0, 0, 0.2);
    }

    body /deep/ p {
      /* deep 能穿透多层 */
      border: 1px solid #00acc1;
    }

    #parent-host::shadow #child-host::shadow p {
      color: blue;
    }
  </style>
  <template id="child-template">
    <p>I am blue.</p>
  </template>
  <template id="parent-template">
    <p>I am the default color.</p>
    <div id="child-host"></div>
  </template>
</head>
<body>
<p>Body</p>
<div id="parent-host"></div>
<script>
  var parentTemplate = document.querySelector("#parent-template");
  var childTemplate = document.querySelector("#child-template");
  var parentRoot = document.querySelector("#parent-host").createShadowRoot();
  var childRoot;

  parentRoot.appendChild(parentTemplate.content);
  childRoot = parentRoot.querySelector("#child-host").createShadowRoot();
  childRoot.appendChild(childTemplate.content);
</script>
</body>
</html>